<?php

/**
 * Project filter form base class.
 *
 * @package    packagesdispenser
 * @subpackage filter
 * @author     Nicolas Surian aka NairuS <contact@nairus.fr>
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseProjectFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'name'                => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'owner'               => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Maintainer'), 'add_empty' => true)),
      'description'         => new sfWidgetFormFilterInput(),
      'href'                => new sfWidgetFormFilterInput(),
      'license_title'       => new sfWidgetFormFilterInput(),
      'license_href'        => new sfWidgetFormFilterInput(),
      'php_version'         => new sfWidgetFormFilterInput(),
      'destination'         => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'path'                => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'readme'              => new sfWidgetFormFilterInput(),
      'release_policy'      => new sfWidgetFormChoice(array('choices' => array('' => '', 'auto' => 'auto', 'manual' => 'manual'))),
      'repository'          => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('RepositoryType'), 'add_empty' => true)),
      'repository_username' => new sfWidgetFormFilterInput(),
      'repository_password' => new sfWidgetFormFilterInput(),
      'summary'             => new sfWidgetFormFilterInput(),
      'version'             => new sfWidgetFormFilterInput(),
      'created_at'          => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'          => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'maintainers_list'    => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Maintainer')),
    ));

    $this->setValidators(array(
      'name'                => new sfValidatorPass(array('required' => false)),
      'owner'               => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Maintainer'), 'column' => 'id')),
      'description'         => new sfValidatorPass(array('required' => false)),
      'href'                => new sfValidatorPass(array('required' => false)),
      'license_title'       => new sfValidatorPass(array('required' => false)),
      'license_href'        => new sfValidatorPass(array('required' => false)),
      'php_version'         => new sfValidatorPass(array('required' => false)),
      'destination'         => new sfValidatorPass(array('required' => false)),
      'path'                => new sfValidatorPass(array('required' => false)),
      'readme'              => new sfValidatorPass(array('required' => false)),
      'release_policy'      => new sfValidatorChoice(array('required' => false, 'choices' => array('auto' => 'auto', 'manual' => 'manual'))),
      'repository'          => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('RepositoryType'), 'column' => 'url')),
      'repository_username' => new sfValidatorPass(array('required' => false)),
      'repository_password' => new sfValidatorPass(array('required' => false)),
      'summary'             => new sfValidatorPass(array('required' => false)),
      'version'             => new sfValidatorPass(array('required' => false)),
      'created_at'          => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'          => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'maintainers_list'    => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Maintainer', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('project_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addMaintainersListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.ProjectMaintainer ProjectMaintainer')
      ->andWhereIn('ProjectMaintainer.maintainer_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'Project';
  }

  public function getFields()
  {
    return array(
      'id'                  => 'Number',
      'name'                => 'Text',
      'owner'               => 'ForeignKey',
      'description'         => 'Text',
      'href'                => 'Text',
      'license_title'       => 'Text',
      'license_href'        => 'Text',
      'php_version'         => 'Text',
      'destination'         => 'Text',
      'path'                => 'Text',
      'readme'              => 'Text',
      'release_policy'      => 'Enum',
      'repository'          => 'ForeignKey',
      'repository_username' => 'Text',
      'repository_password' => 'Text',
      'summary'             => 'Text',
      'version'             => 'Text',
      'created_at'          => 'Date',
      'updated_at'          => 'Date',
      'maintainers_list'    => 'ManyKey',
    );
  }
}
